#
# @lc app=leetcode.cn id=93 lang=python
#
# [93] 复原 IP 地址
#

# @lc code=start
class Solution(object):
    def restoreIpAddresses(self, s):
        """
        :type s: str
        :rtype: List[str]
        """
        self.s = s
        self.result = []
        self.sub = []
        self.loop(0)
        return self.result

    def loop(self, index):
        if len(self.sub) == 4:
            if index == len(self.s):
                self.result.append('.'.join(self.sub))
            return

        for i in range(index, len(self.s)):
            string = self.s[index: i+1]
            if int(string) >= 0 and int(string) <= 255:
                if len(string)>1 and int(string[0])==0:
                    continue
                self.sub.append(string)
                self.loop(i+1)
                self.sub.pop()
        
# @lc code=end

